home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 26 / Cream of the Crop 26.iso / os2 / octa209s.zip / octave-2.09 / src / op-cs-m.cc < prev    next >
C/C++ Source or Header  |  1997-01-24  |  7KB  |  250 lines

  1. /*
  2.  
  3. Copyright (C) 1996 John W. Eaton
  4.  
  5. This file is part of Octave.
  6.  
  7. Octave is free software; you can redistribute it and/or modify it
  8. under the terms of the GNU General Public License as published by the
  9. Free Software Foundation; either version 2, or (at your option) any
  10. later version.
  11.  
  12. Octave is distributed in the hope that it will be useful, but WITHOUT
  13. ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  14. FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  15. for more details.
  16.  
  17. You should have received a copy of the GNU General Public License
  18. along with Octave; see the file COPYING.  If not, write to the Free
  19. Software Foundation, 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
  20.  
  21. */
  22.  
  23. #if defined (__GNUG__)
  24. #pragma implementation
  25. #endif
  26.  
  27. #ifdef HAVE_CONFIG_H
  28. #include <config.h>
  29. #endif
  30.  
  31. #include "gripes.h"
  32. #include "ov.h"
  33. #include "ov-complex.h"
  34. #include "ov-cx-mat.h"
  35. #include "ov-re-mat.h"
  36. #include "ov-typeinfo.h"
  37. #include "op-cs-m.h"
  38. #include "ops.h"
  39. #include "xdiv.h"
  40. #include "xpow.h"
  41.  
  42. // complex scalar by matrix ops.
  43.  
  44. static octave_value
  45. add (const octave_value& a1, const octave_value& a2)
  46. {
  47.   CAST_BINOP_ARGS (const octave_complex&, const octave_matrix&);
  48.  
  49.   return octave_value (v1.complex_value () + v2.matrix_value ());
  50. }
  51.  
  52. static octave_value
  53. sub (const octave_value& a1, const octave_value& a2)
  54. {
  55.   CAST_BINOP_ARGS (const octave_complex&, const octave_matrix&);
  56.  
  57.   return octave_value (v1.complex_value () - v2.matrix_value ());
  58. }
  59.  
  60. static octave_value
  61. mul (const octave_value& a1, const octave_value& a2)
  62. {
  63.   CAST_BINOP_ARGS (const octave_complex&, const octave_matrix&);
  64.  
  65.   return octave_value (v1.complex_value () * v2.matrix_value ());
  66. }
  67.  
  68. static octave_value
  69. div (const octave_value&, const octave_value& v2)
  70. {
  71.   gripe_nonconformant ("operator /", 1, 1, v2.rows (), v2.columns ());
  72.   return octave_value ();
  73. }
  74.  
  75. static octave_value
  76. pow (const octave_value& a1, const octave_value& a2)
  77. {
  78.   CAST_BINOP_ARGS (const octave_complex&, const octave_matrix&);
  79.  
  80.   return xpow (v1.complex_value (), v2.matrix_value ());
  81. }
  82.  
  83. static octave_value
  84. ldiv (const octave_value& a1, const octave_value& a2)
  85. {
  86.   CAST_BINOP_ARGS (const octave_complex&, const octave_matrix&);
  87.  
  88.   Complex d = v1.complex_value ();
  89.  
  90.   if (d == 0.0)
  91.     gripe_divide_by_zero ();
  92.  
  93.   return octave_value (v2.matrix_value () / d);
  94. }
  95.  
  96. #define BOOL_OP(OP, EMPTY_RESULT) \
  97.   SC_MX_BOOL_OP (Complex, s, v1.complex_value (), \
  98.          Matrix, m, v2.matrix_value (), \
  99.          real (s) OP m (i, j), EMPTY_RESULT)
  100.  
  101. static octave_value
  102. lt (const octave_value& a1, const octave_value& a2)
  103. {
  104.   CAST_BINOP_ARGS (const octave_complex&, const octave_matrix&);
  105.  
  106.   BOOL_OP (<, Matrix ());
  107. }
  108.  
  109. static octave_value
  110. le (const octave_value& a1, const octave_value& a2)
  111. {
  112.   CAST_BINOP_ARGS (const octave_complex&, const octave_matrix&);
  113.  
  114.   BOOL_OP (<=, Matrix ());
  115. }
  116.  
  117. static octave_value
  118. eq (const octave_value& a1, const octave_value& a2)
  119. {
  120.   CAST_BINOP_ARGS (const octave_complex&, const octave_matrix&);
  121.  
  122.   SC_MX_BOOL_OP (Complex, s, v1.complex_value (),
  123.          Matrix, m, v2.matrix_value (),
  124.          s == m (i, j), 0.0);
  125. }
  126.  
  127. static octave_value
  128. ge (const octave_value& a1, const octave_value& a2)
  129. {
  130.   CAST_BINOP_ARGS (const octave_complex&, const octave_matrix&);
  131.  
  132.   BOOL_OP (>=, Matrix ());
  133. }
  134.  
  135. static octave_value
  136. gt (const octave_value& a1, const octave_value& a2)
  137. {
  138.   CAST_BINOP_ARGS (const octave_complex&, const octave_matrix&);
  139.  
  140.   BOOL_OP (>, Matrix ());
  141. }
  142.  
  143. static octave_value
  144. ne (const octave_value& a1, const octave_value& a2)
  145. {
  146.   CAST_BINOP_ARGS (const octave_complex&, const octave_matrix&);
  147.  
  148.   SC_MX_BOOL_OP (Complex, s, v1.complex_value (),
  149.          Matrix, m, v2.matrix_value (),
  150.          s != m (i, j), 1.0);
  151. }
  152.  
  153. static octave_value
  154. el_mul (const octave_value& a1, const octave_value& a2)
  155. {
  156.   CAST_BINOP_ARGS (const octave_complex&, const octave_matrix&);
  157.  
  158.   return octave_value (v1.complex_value () * v2.matrix_value ());
  159. }
  160.  
  161. static octave_value
  162. el_div (const octave_value& a1, const octave_value& a2)
  163. {
  164.   CAST_BINOP_ARGS (const octave_complex&, const octave_matrix&);
  165.  
  166.   return x_el_div (v1.complex_value (), v2.matrix_value ());
  167. }
  168.  
  169. static octave_value
  170. el_pow (const octave_value& a1, const octave_value& a2)
  171. {
  172.   CAST_BINOP_ARGS (const octave_complex&, const octave_matrix&);
  173.  
  174.   return elem_xpow (v1.complex_value (), v2.matrix_value ());
  175. }
  176.  
  177. static octave_value
  178. el_ldiv (const octave_value& a1, const octave_value& a2)
  179. {
  180.   CAST_BINOP_ARGS (const octave_complex&, const octave_matrix&);
  181.  
  182.   Complex d = v1.complex_value ();
  183.  
  184.   if (d == 0.0)
  185.     gripe_divide_by_zero ();
  186.  
  187.   return octave_value (v2.matrix_value () / d);
  188. }
  189.  
  190. static octave_value
  191. el_and (const octave_value& a1, const octave_value& a2)
  192. {
  193.   CAST_BINOP_ARGS (const octave_complex&, const octave_matrix&);
  194.  
  195.   SC_MX_BOOL_OP (Complex, s, v1.complex_value (), \
  196.          Matrix, m, v2.matrix_value (), \
  197.          s != 0.0 && m (i, j), Matrix ());
  198. }
  199.  
  200. static octave_value
  201. el_or (const octave_value& a1, const octave_value& a2)
  202. {
  203.   CAST_BINOP_ARGS (const octave_complex&, const octave_matrix&);
  204.  
  205.   SC_MX_BOOL_OP (Complex, s, v1.complex_value (), \
  206.          Matrix, m, v2.matrix_value (), \
  207.          s != 0.0 || m (i, j), Matrix ());
  208. }
  209.  
  210. static octave_value *
  211. complex_matrix_conv (const octave_value& a)
  212. {
  213.   CAST_CONV_ARG (const octave_complex&);
  214.  
  215.   return new octave_complex_matrix (v.complex_matrix_value ());
  216. }
  217.  
  218. void
  219. install_cs_m_ops (void)
  220. {
  221.   INSTALL_BINOP (add, octave_complex, octave_matrix, add);
  222.   INSTALL_BINOP (sub, octave_complex, octave_matrix, sub);
  223.   INSTALL_BINOP (mul, octave_complex, octave_matrix, mul);
  224.   INSTALL_BINOP (div, octave_complex, octave_matrix, div);
  225.   INSTALL_BINOP (pow, octave_complex, octave_matrix, pow);
  226.   INSTALL_BINOP (ldiv, octave_complex, octave_matrix, ldiv);
  227.   INSTALL_BINOP (lt, octave_complex, octave_matrix, lt);
  228.   INSTALL_BINOP (le, octave_complex, octave_matrix, le);
  229.   INSTALL_BINOP (eq, octave_complex, octave_matrix, eq);
  230.   INSTALL_BINOP (ge, octave_complex, octave_matrix, ge);
  231.   INSTALL_BINOP (gt, octave_complex, octave_matrix, gt);
  232.   INSTALL_BINOP (ne, octave_complex, octave_matrix, ne);
  233.   INSTALL_BINOP (el_mul, octave_complex, octave_matrix, el_mul);
  234.   INSTALL_BINOP (el_div, octave_complex, octave_matrix, el_div);
  235.   INSTALL_BINOP (el_pow, octave_complex, octave_matrix, el_pow);
  236.   INSTALL_BINOP (el_ldiv, octave_complex, octave_matrix, el_ldiv);
  237.   INSTALL_BINOP (el_and, octave_complex, octave_matrix, el_and);
  238.   INSTALL_BINOP (el_or, octave_complex, octave_matrix, el_or);
  239.  
  240.   INSTALL_ASSIGNCONV (octave_complex, octave_matrix, octave_complex_matrix);
  241.  
  242.   INSTALL_WIDENOP (octave_complex, octave_complex_matrix, complex_matrix_conv);
  243. }
  244.  
  245. /*
  246. ;;; Local Variables: ***
  247. ;;; mode: C++ ***
  248. ;;; End: ***
  249. */
  250.